package com.zz.spring6.resources;

import org.springframework.core.io.FileSystemResource;

import java.io.IOException;
import java.io.InputStream;

/**
 * 访问系统资源
 */
public class FileSystemResourceDemo {

    public static void main(String[] args) {
        // 相对路径
        //loadFileSystemResourceDemo("E:\\java\\idea\\a\\spring6\\spring6-resources\\src\\main\\resources\\zz.txt");
        // 相对路径
        loadFileSystemResourceDemo("zz.txt");
    }

    public static void loadFileSystemResourceDemo(String path){
        FileSystemResource resource = new FileSystemResource(path);
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());
        try {
            InputStream in = resource.getInputStream();
            byte[] b = new byte[1024];
            while (in.read(b) != -1){
                System.out.println("11"+new String(b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
